<!-- build time:Tue Jul 21 2020 12:41:23 GMT+0800 (GMT+08:00) --><!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=2"><meta name="theme-color" content="#222"><meta name="generator" content="Hexo 4.2.0"><link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png"><link rel="icon" type="image/png" sizes="32x32" href="/img/blog_favicon/favicon-32x32-next.png"><link rel="icon" type="image/png" sizes="16x16" href="/img/blog_favicon/favicon-16x16-next.png"><link rel="mask-icon" href="/images/logo.svg" color="#222"><meta name="baidu-site-verification" content="r15J5zOS2KI43yBS"><link rel="stylesheet" href="/css/main.css"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"><link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/themes/blue/pace-theme-minimal.min.css"><script src="//cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/pace.min.js"></script><script id="hexo-configurations">var NexT=window.NexT||{},CONFIG={hostname:new URL("http://www.zhengjiaao.cn").hostname,root:"/",scheme:"Muse",version:"7.6.0",exturl:!1,sidebar:{position:"left",display:"post",padding:18,offset:12,onmobile:!1},copycode:{enable:!0,show_result:!0,style:null},back2top:{enable:!0,sidebar:!1,scrollpercent:!0},bookmark:{enable:!0,color:"#222",save:"auto"},fancybox:!0,mediumzoom:!1,lazyload:!1,pangu:!1,comments:{style:"tabs",active:"valine",storage:!0,lazyload:!1,nav:null,activeClass:"valine"},algolia:{appID:"",apiKey:"",indexName:"",hits:{per_page:10},labels:{input_placeholder:"Search for Posts",hits_empty:"We didn't find any results for the search: ${query}",hits_stats:"${hits} results found in ${time} ms"}},localsearch:{enable:!0,trigger:"auto",top_n_per_article:1,unescape:!1,preload:!1},path:"search.xml",motion:{enable:!0,async:!1,transition:{post_block:"fadeIn",post_header:"slideDownIn",post_body:"slideDownIn",coll_header:"slideLeftIn",sidebar:"slideUpIn"}}}</script><meta property="og:type" content="article"><meta property="og:title" content="springboot-Solr-史上最详细"><meta property="og:url" content="http://www.zhengjiaao.cn/posts/200750558.html"><meta property="og:site_name" content="宇宙小神特别萌"><meta property="og:locale" content="zh_CN"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-b504390c241fbf59.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-32e0fcd2d0a218a8.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-f4d7c30e447827fb.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-15fc9e61f41246f2.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-2c47d9d5c35e50d9.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-e557a3d13152974c.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-31afc1bfb97a8a8a.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-325496792474dd34.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-e6581bae4f7b8bda.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-df064abff2566b9c.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-bcc42b7a6ee1aa0a.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-6ef1a9585bc97203.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-7f6267746f53fcb7.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-47de4575a8a6832c.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-2c44cac3ea431294.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-e7752c1bb89d3ed1.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-e33d2bf46d0a14e3.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-ba7bba480f988d86.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-a982e542a4b04a89.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-2aae26ad752d1edc.png"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-2abf126a9d3bd475.jpg"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-66254e8783595611.jpg"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-ebbc86973da7a007.jpg"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-5c0bfceb26de7c2c.jpg"><meta property="og:image" content="https://upload-images.jianshu.io/upload_images/15645795-7c5e4df5e44d12a8.jpg"><meta property="article:published_time" content="2020-01-03T08:14:50.000Z"><meta property="article:modified_time" content="2020-07-20T11:38:38.628Z"><meta property="article:author" content="宇宙小神特别萌"><meta property="article:tag" content="SpringBoot"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="https://upload-images.jianshu.io/upload_images/15645795-b504390c241fbf59.png"><link rel="canonical" href="http://www.zhengjiaao.cn/posts/200750558.html"><script id="page-configurations">CONFIG.page={sidebar:"",isHome:!1,isPost:!0}</script><title>springboot-Solr-史上最详细 | 宇宙小神特别萌</title><noscript><style>.sidebar-inner,.use-motion .brand,.use-motion .collection-header,.use-motion .comments,.use-motion .menu-item,.use-motion .pagination,.use-motion .post-block,.use-motion .post-body,.use-motion .post-header{opacity:initial}.use-motion .site-subtitle,.use-motion .site-title{opacity:initial;top:initial}.use-motion .logo-line-before i{left:initial}.use-motion .logo-line-after i{right:initial}</style></noscript><link rel="alternate" href="/atom.xml" title="宇宙小神特别萌" type="application/atom+xml"></head><body itemscope itemtype="http://schema.org/WebPage"><div class="container use-motion"><div class="headband"></div><header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="header-inner"><div class="site-brand-container"><div class="site-meta custom-logo"><div class="site-meta-headline"><a><img class="custom-logo-image" src="/img/blog_favicon/favicon-32x32-next.png" alt="宇宙小神特别萌"></a></div><div><a href="/" class="brand" rel="start"><span class="logo-line-before"><i></i></span> <span class="site-title">宇宙小神特别萌</span> <span class="logo-line-after"><i></i></span></a></div><p class="site-subtitle">ZhengJa</p></div><div class="site-nav-toggle"><div class="toggle" aria-label="切换导航栏"><span class="toggle-line toggle-line-first"></span> <span class="toggle-line toggle-line-middle"></span> <span class="toggle-line toggle-line-last"></span></div></div></div><nav class="site-nav"><ul id="menu" class="menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签<span class="badge">27</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档<span class="badge">116</span></a></li><li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-fw fa-sitemap"></i>站点地图</a></li><li class="menu-item menu-item-messageboard"><a href="/messageboard/" rel="section"><i class="fa fa-fw fa-address-book"></i>留言板</a></li><li class="menu-item menu-item-links"><a href="/links/" rel="section"><i class="fa fa-fw fa-user-plus"></i>友链</a></li><li class="menu-item menu-item-shuoshuo"><a href="/shuoshuo/" rel="section"><i class="fa fa-fw fa-file-text-o"></i>说说</a></li><li class="menu-item menu-item-search"><a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索</a></li></ul></nav><div class="site-search"><div class="popup search-popup"><div class="search-header"><span class="search-icon"><i class="fa fa-search"></i></span><div class="search-input-container"><input autocomplete="off" autocorrect="off" autocapitalize="none" placeholder="搜索..." spellcheck="false" type="text" id="search-input"></div><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span></div><div id="search-result"></div></div><div class="search-pop-overlay"></div></div></div></header><div class="back-to-top"><i class="fa fa-arrow-up"></i> <span>0%</span></div><div class="reading-progress-bar"></div><a role="button" class="book-mark-link book-mark-link-fixed"></a> <a href="https://github.com/zhengjiaao" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin:130px 106px" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><main class="main"><div class="main-inner"><div class="content-wrap"><div class="content"><div class="posts-expand"><article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN"><link itemprop="mainEntityOfPage" href="http://www.zhengjiaao.cn/posts/200750558.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="image" content="/my-images/avatar.gif"><meta itemprop="name" content="宇宙小神特别萌"><meta itemprop="description" content="人生就是一次幸运的旅行！"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="宇宙小神特别萌"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">springboot-Solr-史上最详细</h1><div class="post-meta"><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-calendar-o"></i> </span><span class="post-meta-item-text">发表于</span> <time title="创建时间：2020-01-03 16:14:50" itemprop="dateCreated datePublished" datetime="2020-01-03T16:14:50+08:00">2020-01-03</time> </span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-calendar-check-o"></i> </span><span class="post-meta-item-text">更新于</span> <time title="修改时间：2020-07-20 19:38:38" itemprop="dateModified" datetime="2020-07-20T19:38:38+08:00">2020-07-20</time> </span><span id="/posts/200750558.html" class="post-meta-item leancloud_visitors" data-flag-title="springboot-Solr-史上最详细" title="热度"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="post-meta-item-text">热度：</span> <span class="leancloud-visitors-count"></span> <span>℃</span> </span><span class="post-meta-item" title="热度" id="busuanzi_container_page_pv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="post-meta-item-text">热度：</span> <span id="busuanzi_value_page_pv"></span> </span><span class="post-meta-item"><span class="post-meta-item-icon"><i class="fa fa-comment-o"></i> </span><span class="post-meta-item-text">Valine：</span> <a title="valine" href="/posts/200750558.html#comments" itemprop="discussionUrl"><span class="post-comments-count valine-comment-count" data-xid="/posts/200750558.html" itemprop="commentCount"></span></a></span><br><span class="post-meta-item" title="本文字数"><span class="post-meta-item-icon"><i class="fa fa-file-word-o"></i> </span><span class="post-meta-item-text">本文字数：</span> <span>21k</span> </span><span class="post-meta-item" title="阅读时长"><span class="post-meta-item-icon"><i class="fa fa-clock-o"></i> </span><span class="post-meta-item-text">阅读时长 &asymp;</span> <span>19 分钟</span></span></div></header><div class="post-body" itemprop="articleBody"><meta name="referrer" content="no-referrer"><a id="more"></a><p><img src="https://upload-images.jianshu.io/upload_images/15645795-b504390c241fbf59.png" alt="全文检索目录.png"></p><h3 id="一、Solr"><a href="#一、Solr" class="headerlink" title="一、Solr"></a>一、Solr</h3><p>官网下载：<a href="https://lucene.apache.org/solr/downloads.html" target="_blank" rel="noopener">https://lucene.apache.org/solr/downloads.html</a></p><h4 id="1、下载-zip-为windows版"><a href="#1、下载-zip-为windows版" class="headerlink" title="1、下载 .zip 为windows版"></a>1、下载 <strong>.zip</strong> 为windows版</h4><p>我下载的最新版本solr-8.2.0：内嵌jeety服务器 ，solr5之前的版本都需要放到自己的tomcat里.<br>下载：<a href="http://mirror.bit.edu.cn/apache/lucene/solr/8.2.0/solr-8.2.0.zip" target="_blank" rel="noopener"><strong>solr-8.2.0.zip</strong></a><br>安装：<br>下载完成之后放在的D:\solr-8.2.0目录下 ，然后解压到当前目录<br>解压结构目录说明：<br>​ 还有一个：server文件夹 ，图示比较老的 ，没有显示server。</p><p><img src="https://upload-images.jianshu.io/upload_images/15645795-32e0fcd2d0a218a8.png" alt="solr安装目录结构.png"></p><h4 id="2、启动、关闭solr"><a href="#2、启动、关闭solr" class="headerlink" title="2、启动、关闭solr"></a>2、启动、关闭solr</h4><p>　　在解压之后的solr目录中找到bin文件夹 ，进去之后右键进入Powershell输入以下命令：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"># 启动 </span><br><span class="line">.\solr start</span><br></pre></td></tr></table></figure><p>其它命令：</p><figure class="highlight cmd"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"># 启动 </span><br><span class="line">.\solr <span class="built_in">start</span></span><br><span class="line"># 关闭 </span><br><span class="line">.\solr stop -all</span><br><span class="line"></span><br><span class="line"># 步骤：</span><br><span class="line"># 启动 Solr 将默认监听 <span class="number">8983</span> 端口 ，其中 -m <span class="number">1</span>g 指定分配给 JVM 的内存为 <span class="number">1</span> G</span><br><span class="line">.\solr <span class="built_in">start</span> -m <span class="number">1</span>g</span><br><span class="line"></span><br><span class="line"># 接下来我们创建一个solr应用:在solr的目录下生成应用对应的文件夹wenda ，这个文件夹非常重要 ，后面我们会在该文件夹下 ，配置文件来实现中文检索</span><br><span class="line">.\solr create -c wenda</span><br></pre></td></tr></table></figure><p>测试启动是否成功：<br>其中8983是默认端口号。此时在浏览器输入网址 <a href="http://localhost:8983/solr/#/" target="_blank" rel="noopener">http://localhost:8983/solr/#/</a><br>成功的话即可看到如下图界面。</p><p><img src="https://upload-images.jianshu.io/upload_images/15645795-f4d7c30e447827fb.png" alt="启动成功页面.png"></p><h4 id="3、创建core文件夹"><a href="#3、创建core文件夹" class="headerlink" title="3、创建core文件夹"></a>3、创建core文件夹</h4><p>两种方式效果一样 ，方式一方便而已。</p><h5 id="创建core文件夹方式一-推荐-："><a href="#创建core文件夹方式一-推荐-：" class="headerlink" title="创建core文件夹方式一(推荐)："></a>创建core文件夹方式一(推荐)：</h5><p>cmd在solr-8.2.0/solr/bin目录下（注意 ，需要在solr start启动solr后才能创建）输入:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">.\solr create -c corename    # （core名称 ，自定义）命令创建一个core</span><br></pre></td></tr></table></figure><p>重启：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">.\solr stop -all</span><br><span class="line"></span><br><span class="line"> 启动 </span><br><span class="line">.\solr start</span><br></pre></td></tr></table></figure><p>运行完成后在浏览器中访问 <a href="http://localhost:8983/solr/#/（刷新页面）可以看到如下图所示" target="_blank" rel="noopener">http://localhost:8983/solr/#/（刷新页面）可以看到如下图所示</a> ，新创建的core被添加进去</p><p><img src="https://upload-images.jianshu.io/upload_images/15645795-15fc9e61f41246f2.png" alt="创建的corename.png"></p><p>此时打开文件夹D:\solr-8.2.0\server\solr可以看到下面多了一个corename文件夹 ，就是我们刚才创建的core。创建core可以直接在文件夹操作 ，百度上可以收到。这里为了方便使用命令创建。</p><h5 id="创建core文件夹方式二："><a href="#创建core文件夹方式二：" class="headerlink" title="创建core文件夹方式二："></a>创建core文件夹方式二：</h5><p>在solr目录中的\server\solr文件夹中创建一个文件夹 ，我这边文件夹名称叫做core(名称随便起)。然后把\server\solr\configsets\sample_techproducts_configs下面的conf文件夹复制到刚才创建的core文件夹下面。</p><p>完成上面操作之后启动solr ，启动成功之后打开浏览器进入地址：&lt; <a href="http://127.0.0.1:8983/solr/#/&gt;" target="_blank" rel="noopener">http://127.0.0.1:8983/solr/#/&gt;</a></p><p>可以看见solr的管理界面 ，点击左侧的Core Admin ，在新页面的name和instanceDir输入框中分别修改为刚才创建的文件夹名称(我这里是core) ，然后点击下面Add Core按钮即可成功创建core。</p><p>创建成功之后 ，会在你刚才创建的core文件夹下面生成一个文件夹和一个文件<em>.properties ，*</em>这样即表示创建成功**。</p><h4 id="4、创建springboot项目和测试代码"><a href="#4、创建springboot项目和测试代码" class="headerlink" title="4、创建springboot项目和测试代码"></a>4、创建springboot项目和测试代码</h4><p>（solr在项目中使用：此处连接的是core ，方式二创建的；也可以连接方式一创建的corename）<br>pom.xml依赖</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-data-solr<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure><p>具体pom文件内容：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-web<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-test<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">scope</span>&gt;</span>test<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.springframework.boot<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>spring-boot-starter-tomcat<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">scope</span>&gt;</span>provided<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="comment">&lt;!--集成swagger-API--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.swagger<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>swagger-models<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.5.21<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--&lt;scope&gt;compile&lt;/scope&gt;--&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.swagger<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>swagger-annotations<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.5.21<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    <span class="comment">&lt;!--&lt;scope&gt;compile&lt;/scope&gt;--&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.springfox<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>springfox-swagger-ui<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.9.2<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.springfox<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>springfox-swagger2<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">version</span>&gt;</span>2.9.2<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">exclusions</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">exclusion</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.swagger<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>swagger-models<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">exclusion</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">exclusion</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>io.swagger<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">            <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>swagger-annotations<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;/<span class="name">exclusion</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">exclusions</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br></pre></td></tr></table></figure><p>.yml文件</p><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">server:</span></span><br><span class="line">  <span class="attr">context-path:</span> <span class="string">/</span></span><br><span class="line">  <span class="attr">port:</span> <span class="number">8080</span></span><br><span class="line"><span class="attr">spring:</span></span><br><span class="line">  <span class="attr">data:</span></span><br><span class="line">    <span class="attr">solr:</span></span><br><span class="line">      <span class="comment">#后面这个core就是文件夹的名称 ，这里也可以不用写这个 ，如果这里不指定core ，那么在代码中使用的时候 ，就需要指定core。</span></span><br><span class="line">      <span class="comment">#代码中可以指定core的地方有注释可以看</span></span><br><span class="line">      <span class="attr">host:</span>  <span class="string">http://127.0.0.1:8983/solr/core</span></span><br></pre></td></tr></table></figure><p>添加swagger2配置<br>创建文件夹：config\Swagger2Config.java</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">package</span> com.dist.config;</span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> com.google.common.base.Predicate;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Bean;</span><br><span class="line"><span class="keyword">import</span> org.springframework.context.annotation.Configuration;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.builders.ApiInfoBuilder;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.builders.PathSelectors;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.service.ApiInfo;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.service.Contact;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.spi.DocumentationType;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.spring.web.plugins.Docket;</span><br><span class="line"><span class="keyword">import</span> springfox.documentation.swagger2.annotations.EnableSwagger2;</span><br><span class="line"></span><br><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@author</span> yangmin</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@date</span> 2018/8/15</span></span><br><span class="line"><span class="comment"> * <span class="doctag">@desc</span></span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@EnableSwagger</span>2</span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Swagger2Config</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Bean</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> Docket <span class="title">adminApi</span><span class="params">()</span></span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> Docket(DocumentationType.SWAGGER_2)</span><br><span class="line">                .groupName(<span class="string">"Admin API"</span>)</span><br><span class="line">                .forCodeGeneration(<span class="keyword">true</span>)</span><br><span class="line">                .pathMapping(<span class="string">"/"</span>)</span><br><span class="line">                .select()</span><br><span class="line">                .paths(paths())</span><br><span class="line">                .build()</span><br><span class="line">                .apiInfo(apiInfo())</span><br><span class="line">                .useDefaultResponseMessages(<span class="keyword">false</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> Predicate&lt;String&gt; <span class="title">paths</span><span class="params">()</span></span>&#123;</span><br><span class="line">        <span class="keyword">return</span> PathSelectors.regex(<span class="string">"^/(?!error).*$"</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> ApiInfo <span class="title">apiInfo</span><span class="params">()</span></span>&#123;</span><br><span class="line">        Contact contact = <span class="keyword">new</span> Contact(<span class="string">"BaiDu"</span>, <span class="string">"controller://baidu.com"</span>, <span class="string">" zhengja@dist.com.cn"</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> ApiInfoBuilder()</span><br><span class="line">                .title(<span class="string">"个人SpringBoot测试系统"</span>)</span><br><span class="line">                .description(<span class="string">"开发API文档"</span>)</span><br><span class="line">                .contact(contact)</span><br><span class="line">                .version(<span class="string">"1.0"</span>)</span><br><span class="line">                .build();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>在resources/static下创建index.html<br>把以下内容复制 ，需要更改端口和项目地址</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html lang&#x3D;&quot;en&quot;&gt;</span><br><span class="line">&lt;head&gt;</span><br><span class="line">    &lt;meta charset&#x3D;&quot;UTF-8&quot;&gt;</span><br><span class="line">    &lt;title&gt;Title&lt;&#x2F;title&gt;</span><br><span class="line">&lt;&#x2F;head&gt;</span><br><span class="line">&lt;body&gt;</span><br><span class="line">&lt;h1&gt;进入首页&lt;&#x2F;h1&gt;</span><br><span class="line">&lt;a href&#x3D;&quot; http:&#x2F;&#x2F;localhost:8080&#x2F;swagger-ui.html&quot;&gt;进入swagger页面测试2&lt;&#x2F;a&gt;</span><br><span class="line">&lt;&#x2F;body&gt;</span><br><span class="line">&lt;&#x2F;html&gt;</span><br></pre></td></tr></table></figure><p>controller下SolrController.java类</p><figure class="highlight plain"><figcaption><span>com.dist.controller;</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">import io.swagger.annotations.Api;</span><br><span class="line">import io.swagger.annotations.ApiOperation;</span><br><span class="line">import io.swagger.annotations.ApiParam;</span><br><span class="line">import org.apache.solr.client.solrj.SolrClient;</span><br><span class="line">import org.apache.solr.client.solrj.SolrQuery;</span><br><span class="line">import org.apache.solr.client.solrj.SolrServerException;</span><br><span class="line">import org.apache.solr.client.solrj.response.QueryResponse;</span><br><span class="line">import org.apache.solr.client.solrj.response.UpdateResponse;</span><br><span class="line">import org.apache.solr.common.SolrDocument;</span><br><span class="line">import org.apache.solr.common.SolrDocumentList;</span><br><span class="line">import org.apache.solr.common.SolrInputDocument;</span><br><span class="line">import org.springframework.beans.factory.annotation.Autowired;</span><br><span class="line">import org.springframework.web.bind.annotation.RequestMapping;</span><br><span class="line">import org.springframework.web.bind.annotation.RequestMethod;</span><br><span class="line">import org.springframework.web.bind.annotation.RequestParam;</span><br><span class="line">import org.springframework.web.bind.annotation.RestController;</span><br><span class="line"></span><br><span class="line">import java.io.IOException;</span><br><span class="line"></span><br><span class="line">&#x2F;**</span><br><span class="line"> * @author zhengja@dist.com.cn</span><br><span class="line"> * @data 2019&#x2F;8&#x2F;15 15:43</span><br><span class="line"> *&#x2F;</span><br><span class="line">@RequestMapping(value &#x3D; &quot;rest&#x2F;solr&quot;)</span><br><span class="line">@RestController</span><br><span class="line">@Api(tags &#x3D; &#123;&quot;SolrController&quot;&#125;,description &#x3D; &quot;Solr 全文检索&quot;)</span><br><span class="line">public class SolrController &#123;</span><br><span class="line"></span><br><span class="line">    @Autowired</span><br><span class="line">    private SolrClient client;</span><br><span class="line"></span><br><span class="line">    @ApiOperation(value &#x3D; &quot;添加文档内容&quot;,notes &#x3D; &quot;向文档中添加域 ，必须有id域 ，域的名称必须在scheme.xml中定义&quot;,httpMethod &#x3D; &quot;GET&quot;)</span><br><span class="line">    @RequestMapping(value &#x3D; &quot;insert&quot;,method &#x3D; RequestMethod.GET)</span><br><span class="line">    public Object validator(@ApiParam(value &#x3D; &quot;name&quot;) @RequestParam String name,</span><br><span class="line">                            @ApiParam(value &#x3D; &quot;age&quot;) @RequestParam String age)&#123;</span><br><span class="line">        try &#123;</span><br><span class="line">            String idStr &#x3D; String.valueOf(System.currentTimeMillis());</span><br><span class="line"></span><br><span class="line">            SolrInputDocument document &#x3D; new SolrInputDocument();</span><br><span class="line">            document.setField(&quot;id&quot;, idStr);</span><br><span class="line">            document.setField(&quot;name&quot;, name);</span><br><span class="line">            document.setField(&quot;age&quot;,age);</span><br><span class="line"></span><br><span class="line">            &#x2F;&#x2F; 把文档对象写入索引库</span><br><span class="line">            client.add(&quot;core&quot;,document);&#x2F;&#x2F;如果配置文件中没有指定core ，这个方法的第一个参数就需要指定core名称,比如client.add(&quot;core&quot;, doc);</span><br><span class="line">            client.commit(&quot;core&quot;);&#x2F;&#x2F;如果配置文件中没有指定core ，这个方法的第一个参数就需要指定core名称client.commit(&quot;core&quot;);</span><br><span class="line">            return idStr;</span><br><span class="line">        &#125; catch (Exception e) &#123;</span><br><span class="line">            e.printStackTrace();</span><br><span class="line">        &#125;</span><br><span class="line">        return &quot;error&quot;;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    @ApiOperation(value &#x3D; &quot;更新文档内容&quot;,notes &#x3D; &quot;更新文档内容 ，跟添加的区别是：id不能变 ，其他的可以变&quot;,httpMethod &#x3D; &quot;GET&quot;)</span><br><span class="line">    @RequestMapping(value &#x3D; &quot;updateDocument&quot;,method &#x3D; RequestMethod.GET)</span><br><span class="line">    public Object updateDocument(@ApiParam(value &#x3D; &quot;idStr&quot;) @RequestParam String idStr,</span><br><span class="line">                               @ApiParam(value &#x3D; &quot;name&quot;) @RequestParam String name,</span><br><span class="line">                               @ApiParam(value &#x3D; &quot;age&quot;) @RequestParam String age) throws Exception&#123;</span><br><span class="line">        &#x2F;&#x2F; 创建一个文档对象, 向文档中添加域 ，必须有id域 ，域的名称必须在scheme.xml中定义</span><br><span class="line">        SolrInputDocument document &#x3D; new SolrInputDocument();</span><br><span class="line">        document.setField(&quot;id&quot;, idStr);</span><br><span class="line">        document.setField(&quot;name&quot;, name);</span><br><span class="line">        document.setField(&quot;age&quot;,age);</span><br><span class="line">        &#x2F;&#x2F; 把文档对象写入索引库</span><br><span class="line">        client.add(&quot;core&quot;,document);</span><br><span class="line">        &#x2F;&#x2F; 提交</span><br><span class="line">        client.commit(&quot;core&quot;);</span><br><span class="line">        return document;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    @ApiOperation(value &#x3D; &quot;全量或增量更新-数据库-没成功&quot;,notes &#x3D; &quot;java操作Solr的全量或增量更新 ，可以结合定时任务做定时全量或增量更新&quot;,httpMethod &#x3D; &quot;PUT&quot;)</span><br><span class="line">    @RequestMapping(value &#x3D; &quot;updateSolrData&quot;,method &#x3D; RequestMethod.PUT)</span><br><span class="line">    public void updateSolrData() throws SolrServerException, IOException &#123;</span><br><span class="line">        &#x2F;&#x2F;创建一个查询对象</span><br><span class="line">        SolrQuery solrQuery &#x3D; new SolrQuery();</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F;增量更新全部完成；注意这里entity的值为solr-data-config.xml里entity标签里的name值</span><br><span class="line">        final String SOLR_DELTA_PARAM &#x3D; &quot;&#x2F;dataimport?command&#x3D;delta-import&amp;entity&#x3D;order_info&amp;clean&#x3D;false&amp;commit&#x3D;true&quot;;</span><br><span class="line">        &#x2F;&#x2F;全量更新全部完成</span><br><span class="line">        final String SOLR_FULL_PARAM &#x3D; &quot;&#x2F;dataimport?command&#x3D;full-import&amp;entity&#x3D;order_info&amp;clean&#x3D;true&amp;commit&#x3D;true&quot;;</span><br><span class="line">        &#x2F;&#x2F;设置更新方式</span><br><span class="line">        solrQuery.setRequestHandler(SOLR_DELTA_PARAM);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F; 执行查询</span><br><span class="line">        QueryResponse query &#x3D; client.query(&quot;core&quot;,solrQuery);</span><br><span class="line"></span><br><span class="line">        &#x2F;&#x2F;提交</span><br><span class="line">        client.commit(&quot;core&quot;);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    @ApiOperation(value &#x3D; &quot;查询文档内容&quot;,notes &#x3D; &quot;查询文档内容&quot;,httpMethod &#x3D; &quot;GET&quot;)</span><br><span class="line">    @RequestMapping(value &#x3D; &quot;queryDocument&quot;,method &#x3D; RequestMethod.GET)</span><br><span class="line">    public Object queryDocument(@ApiParam(value &#x3D; &quot;条件&quot;,defaultValue &#x3D; &quot;*:*&quot;) @RequestParam String condition,</span><br><span class="line">                              @ApiParam(value &#x3D; &quot;连接文件夹 默 core&quot;,defaultValue &#x3D; &quot;core&quot;) @RequestParam String collection,</span><br><span class="line">                              @ApiParam(value &#x3D; &quot;分页起始 默 1&quot;,defaultValue &#x3D; &quot;1&quot;) @RequestParam Integer pageStart,</span><br><span class="line">                              @ApiParam(value &#x3D; &quot;分页结束 默 10&quot;,defaultValue &#x3D; &quot;10&quot;) @RequestParam Integer pageEnd) throws Exception &#123;</span><br><span class="line">        &#x2F;&#x2F; 创建一个查询条件</span><br><span class="line">        SolrQuery solrQuery &#x3D; new SolrQuery();</span><br><span class="line">        &#x2F;&#x2F; 设置查询条件</span><br><span class="line">        solrQuery.setQuery(condition);</span><br><span class="line">        &#x2F;&#x2F; 设置分页</span><br><span class="line">        solrQuery.setStart(pageStart);</span><br><span class="line">        solrQuery.setRows(pageEnd);</span><br><span class="line">        &#x2F;&#x2F; 执行查询</span><br><span class="line">        QueryResponse query &#x3D; client.query(collection,solrQuery);</span><br><span class="line">        &#x2F;&#x2F; 取查询结果</span><br><span class="line">        SolrDocumentList solrDocumentList &#x3D; query.getResults();</span><br><span class="line"></span><br><span class="line">        System.out.println(&quot;总记录数：&quot; + solrDocumentList.getNumFound());</span><br><span class="line"></span><br><span class="line">        for (SolrDocument sd : solrDocumentList) &#123;</span><br><span class="line">            System.out.println(sd.get(&quot;id&quot;));</span><br><span class="line">            System.out.println(sd.get(&quot;name&quot;));</span><br><span class="line">            System.out.println(sd.get(&quot;age&quot;));</span><br><span class="line">        &#125;</span><br><span class="line">        return solrDocumentList;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    @ApiOperation(value &#x3D; &quot;删除文档&quot;,notes &#x3D; &quot;删除文档&quot;,httpMethod &#x3D; &quot;DELETE&quot;)</span><br><span class="line">    @RequestMapping(value &#x3D; &quot;deteleDocument&quot;,method &#x3D; RequestMethod.DELETE)</span><br><span class="line">    public Object deteleDocument(@ApiParam(value &#x3D; &quot;连接文件夹 默 core&quot; ,defaultValue &#x3D; &quot;core&quot;) @RequestParam String collection,</span><br><span class="line">                               @ApiParam(value &#x3D; &quot;idStr&quot;) @RequestParam String idStr) throws Exception &#123;</span><br><span class="line">        &#x2F;&#x2F; 根据id删除</span><br><span class="line">        UpdateResponse response &#x3D; client.deleteById(collection, idStr);</span><br><span class="line">        &#x2F;&#x2F; 根据条件删除</span><br><span class="line">        &#x2F;&#x2F; httpSolrServer.deleteByQuery(&quot;&quot;);</span><br><span class="line">        &#x2F;&#x2F; 提交</span><br><span class="line">        client.commit(collection);</span><br><span class="line"></span><br><span class="line">        return response;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><p>然后启动该项目之后 ，进入&lt; <a href="http://localhost:8080/swagger-ui.html&gt;地址即可测试插入索引操作。插入成功之后" target="_blank" rel="noopener">http://localhost:8080/swagger-ui.html&gt;地址即可测试插入索引操作。插入成功之后</a> ，在solr管理界面的左下方有一个下拉框 ，选择你创建的core之后 ，再选择Query ，往下拖到最后 ，点击Execute Query即可看见你刚才插入的索引。</p><h5 id="其他问题："><a href="#其他问题：" class="headerlink" title="其他问题："></a>其他问题：</h5><p>　　刚才我们代码中插入了两个列(id、name) ，如果你想新增一个列 ，比如名称叫做age ，然后启动项目 ，在插入索引 ，在solr管理平台中就看不见这个列名和列对应的值 ，原因是id、name这两列在solr中已经默认配置了。这种情况解决方式如下：</p><p>　　在你创建的core文件夹下面 ，打开conf文件夹 ，修改里面的managed-schema文件 ，修改地点如下：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">132行后面增加(后面这几行随意位置增加就可以)</span><br><span class="line">&lt;field name&#x3D;&quot;age&quot; type&#x3D;&quot;text_general&quot; indexed&#x3D;&quot;true&quot; stored&#x3D;&quot;true&quot;&#x2F;&gt;</span><br><span class="line"></span><br><span class="line">245行后面增加(后面这几行随意位置增加就可以)</span><br><span class="line">&lt;copyField source&#x3D;&quot;age&quot; dest&#x3D;&quot;text&quot;&#x2F;&gt;</span><br></pre></td></tr></table></figure><p>修改完成之后重启solr ，然后重新插入索引就可以成功操作了。<br>再测试：<br>SolrController.java</p><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">SolrInputDocument doc = <span class="keyword">new</span> SolrInputDocument();</span><br><span class="line">            doc.setField(<span class="string">"id"</span>, idStr);  <span class="comment">//id是默认配置 ，在你创建的core文件夹下面 ，打开conf文件夹 ，修改里面的managed-schema文件</span></span><br><span class="line">            doc.setField(<span class="string">"name"</span>, content); <span class="comment">// name是默认配置</span></span><br><span class="line">            doc.setField(<span class="string">"age"</span>,<span class="string">"23"</span>); <span class="comment">//自定义配置：在你创建的core文件夹下面 ，打开conf文件夹 ，修改里面的managed-schema文件 ，添加列 age</span></span><br></pre></td></tr></table></figure><p>效果图：<br><img src="https://upload-images.jianshu.io/upload_images/15645795-2c47d9d5c35e50d9.png" alt="solr效果.png"></p><h4 id="5-solr连接数据库"><a href="#5-solr连接数据库" class="headerlink" title="5.solr连接数据库"></a>5.solr连接数据库</h4><p>此处测试配置的是oracle数据库 ，用的是方式一创建的corename文件包</p><h5 id="1、添加驱动依赖包"><a href="#1、添加驱动依赖包" class="headerlink" title="1、添加驱动依赖包"></a>1、添加驱动依赖包</h5><p>添加驱动依赖包到如下目录：D:\solr-8.2.0\server\solr-webapp\webapp\WEB-INF\lib ，我使用的oracle数据库 ，添加的是oracle驱动包 ，其他数据库添加相应驱动包ojdbc6.jar即可.<br>ojdbc6.jar下载地址：百度网盘<br>链接：<a href="https://pan.baidu.com/s/1OlNdA32xKGXUTbFzDTLSZQ" target="_blank" rel="noopener">https://pan.baidu.com/s/1OlNdA32xKGXUTbFzDTLSZQ</a> 提取码：bgul<br>我添加的是ojdbc6.jar ，也可以添加其它版本如：ojdbc8.jar 或者是mysql的驱动jar等</p><h5 id="2、配置dataimporthandler相关包"><a href="#2、配置dataimporthandler相关包" class="headerlink" title="2、配置dataimporthandler相关包"></a>2、配置dataimporthandler相关包</h5><p>找到解压目录D:\solr-8.2.0\dist下的solr-dataimporthandler-8.2.0.jar包和solr-dataimporthandler-extras-8.2.0.jar两个包 ，也复制到D:\solr-8.2.0\server\solr-webapp\webapp\WEB-INF\lib目录下</p><h5 id="3、添加数据库配置"><a href="#3、添加数据库配置" class="headerlink" title="3、添加数据库配置"></a>3、添加数据库配置</h5><p>找到目录D:\solr-8.2.0\server\solr\corename\conf下的solrconfig.xml并添加配置</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">   &lt;!-- 数据库配置 --&gt;</span><br><span class="line">&lt;requestHandler name&#x3D;&quot;&#x2F;dataimport&quot; class&#x3D;&quot;org.apache.solr.handler.dataimport.DataImportHandler&quot;&gt; </span><br><span class="line">	&lt;lst name&#x3D;&quot;defaults&quot;&gt;  </span><br><span class="line">		  &lt;str name&#x3D;&quot;config&quot;&gt;data-config2.xml&lt;&#x2F;str&gt;  </span><br><span class="line">	&lt;&#x2F;lst&gt;  </span><br><span class="line">   &lt;&#x2F;requestHandler&gt;</span><br></pre></td></tr></table></figure><h5 id="4、创建data-config2-xml数据库连接配置"><a href="#4、创建data-config2-xml数据库连接配置" class="headerlink" title="4、创建data-config2.xml数据库连接配置"></a>4、创建data-config2.xml数据库连接配置</h5><p>在目录D:\solr-8.2.0\server\solr\corename\conf下新建一个文件data-config2.xml并添加如下内容：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version&#x3D;&quot;1.0&quot; encoding&#x3D;&quot;UTF-8&quot;?&gt;</span><br><span class="line">&lt;dataConfig&gt;</span><br><span class="line">	&lt;dataSource </span><br><span class="line">	type&#x3D;&quot;JdbcDataSource&quot; </span><br><span class="line">	driver&#x3D;&quot;oracle.jdbc.OracleDriver&quot; </span><br><span class="line">	url&#x3D;&quot;jdbc:oracle:thin:@localhost:1521:ORCL&quot; </span><br><span class="line">	user&#x3D;&quot;duke&quot; </span><br><span class="line">	password&#x3D;&quot;duke&quot; &#x2F;&gt; </span><br><span class="line">	&lt;document&gt;</span><br><span class="line">		&lt;entity name&#x3D;&quot;userEntity&quot; query&#x3D;&quot;select </span><br><span class="line">        ID,</span><br><span class="line">        NAME,</span><br><span class="line">        AGE</span><br><span class="line">		from t_user&quot;&gt;</span><br><span class="line">			&lt;field column&#x3D;&quot;ID&quot; name&#x3D;&quot;user_id&quot;&#x2F;&gt; </span><br><span class="line">			&lt;field column&#x3D;&quot;NAME&quot; name&#x3D;&quot;user_name&quot;&#x2F;&gt; </span><br><span class="line">			&lt;field column&#x3D;&quot;AGE&quot; name&#x3D;&quot;user_age&quot;&#x2F;&gt; </span><br><span class="line">		&lt;&#x2F;entity&gt;</span><br><span class="line">	&lt;&#x2F;document&gt;</span><br><span class="line">&lt;&#x2F;dataConfig&gt;</span><br></pre></td></tr></table></figure><p>其中数据库驱动 ，地址 ，表 ，用户名 ，密码和查询sql及字段都需要替换成你自己数据库的相应配置。field的culumn是数据库字段名称(查询出来后没有改别名下),name可以自定义 ，之后就是solr字段名称。</p><h5 id="5、配置managed-schema"><a href="#5、配置managed-schema" class="headerlink" title="5、配置managed-schema"></a>5、配置managed-schema</h5><p>打开文件D:\solr-8.2.0\server\solr\corename\conf下的managed-schema ，并在其中的标签里面添加如下配置：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--字段配置 对应userEntity --&gt;</span><br><span class="line">&lt;field name&#x3D;&quot;u_id&quot; type&#x3D;&quot;string&quot; indexed&#x3D;&quot;true&quot; stored&#x3D;&quot;true&quot;&#x2F;&gt;</span><br><span class="line">&lt;field name&#x3D;&quot;u_age&quot; type&#x3D;&quot;string&quot; indexed&#x3D;&quot;true&quot; stored&#x3D;&quot;true&quot;&#x2F;&gt;</span><br><span class="line">&lt;field name&#x3D;&quot;u_name&quot; type&#x3D;&quot;string&quot; indexed&#x3D;&quot;true&quot; stored&#x3D;&quot;true&quot;&#x2F;&gt;</span><br></pre></td></tr></table></figure><p>注意上面的name需要和前面userEntity配置的字段一样如：<field column="ID" name="user_id"></field></p><h5 id="6、验证是否成功"><a href="#6、验证是否成功" class="headerlink" title="6、验证是否成功"></a>6、验证是否成功</h5><p>关掉之前打开的solr,重新启动。</p><p>cmd到D:\solr-8.2.0\bin目录下输入命令:</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">.\solr stop -all</span><br><span class="line"></span><br><span class="line">.\solr start</span><br></pre></td></tr></table></figure><p>待启动成功后 ，浏览器打开solr地址:</p><p><a href="http://localhost:8983/solr/#/" target="_blank" rel="noopener">http://localhost:8983/solr/#/</a></p><ul><li>导入库中数据</li></ul><p>并按如下图选择好 ，其中的userEntity是你的表名。点击excute执行</p><p><img src="https://upload-images.jianshu.io/upload_images/15645795-e557a3d13152974c.png" alt="将查询库中的数据导入solr.png"></p><p>导入完成后/或刷新页面。</p><ul><li><p>查询导入的所有数据：</p><p><img src="https://upload-images.jianshu.io/upload_images/15645795-31afc1bfb97a8a8a.png" alt="查询效果.png"></p></li></ul><p>数据库连接配置完成！</p><h4 id="6-solr-安装中文分词器"><a href="#6-solr-安装中文分词器" class="headerlink" title="6.solr 安装中文分词器"></a>6.solr 安装中文分词器</h4><p>第一步：下载Ikanalyzer7.x分词器的jar 文件 ，下载地址：<a href="https://search.maven.org/search?q=com.github.magese" target="_blank" rel="noopener">https://search.maven.org/search?q=com.github.magese</a><br><img src="https://upload-images.jianshu.io/upload_images/15645795-325496792474dd34.png" alt="ik-analyzer-solr7.png"></p><p>第二步：将下载的Ikanalyzer7.x.jar 文件拷贝至D:\solr-8.2.0\server\solr-webapp\webapp\WEB-INF\lib<br><img src="https://upload-images.jianshu.io/upload_images/15645795-e6581bae4f7b8bda.png" alt="ik-analyzer-solr7位置.png"></p><p>第三步：在solrHome(solr数据源)文件夹 ，新建一个mycore文件夹 ，D:\solr-8.2.0\server\solr<br><img src="https://upload-images.jianshu.io/upload_images/15645795-df064abff2566b9c.png" alt="新建 mycore.png"></p><p>第四步：把solr-8.1.0安装包中的example→example-DIH→solr→solr下的所有文件拷贝到solrHome(solr数据源)文件夹下的mycore文件夹中。<br><img src="https://upload-images.jianshu.io/upload_images/15645795-bcc42b7a6ee1aa0a.png" alt="复制配置mycore.png"></p><p>data是之后运行才会出来的 ，不用在意；<br><img src="https://upload-images.jianshu.io/upload_images/15645795-6ef1a9585bc97203.png" alt="复制配置mycore2.png"></p><p>第五步：打开solrHome(solr数据源)文件夹中的mycore→conf→managed-schema文件 ，添加如下代码：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&lt;!-- ik分词器 --&gt;</span><br><span class="line">   &lt;fieldType name&#x3D;&quot;text_ik&quot; class&#x3D;&quot;solr.TextField&quot;&gt;</span><br><span class="line">     &lt;analyzer type&#x3D;&quot;index&quot;&gt;</span><br><span class="line">         &lt;tokenizer class&#x3D;&quot;org.wltea.analyzer.lucene.IKTokenizerFactory&quot; useSmart&#x3D;&quot;false&quot; conf&#x3D;&quot;ik.conf&quot;&#x2F;&gt;</span><br><span class="line">         &lt;filter class&#x3D;&quot;solr.LowerCaseFilterFactory&quot;&#x2F;&gt;</span><br><span class="line">     &lt;&#x2F;analyzer&gt;</span><br><span class="line">     &lt;analyzer type&#x3D;&quot;query&quot;&gt;</span><br><span class="line">         &lt;tokenizer class&#x3D;&quot;org.wltea.analyzer.lucene.IKTokenizerFactory&quot; useSmart&#x3D;&quot;true&quot; conf&#x3D;&quot;ik.conf&quot;&#x2F;&gt;</span><br><span class="line">         &lt;filter class&#x3D;&quot;solr.LowerCaseFilterFactory&quot;&#x2F;&gt;</span><br><span class="line">     &lt;&#x2F;analyzer&gt;</span><br><span class="line">   &lt;&#x2F;fieldType&gt;</span><br></pre></td></tr></table></figure><p>第六步：重启solr ，输入： <a href="http://localhost:8983/solr/#/" target="_blank" rel="noopener">http://localhost:8983/solr/#/</a><br><img src="https://upload-images.jianshu.io/upload_images/15645795-7f6267746f53fcb7.png" alt="分词器效果.png"></p><h4 id="7-Solr-界面功能"><a href="#7-Solr-界面功能" class="headerlink" title="7.Solr 界面功能"></a>7.Solr 界面功能</h4><p><img src="https://upload-images.jianshu.io/upload_images/15645795-47de4575a8a6832c.png" alt="Solr界面功能1.png"><br><img src="https://upload-images.jianshu.io/upload_images/15645795-2c44cac3ea431294.png" alt="Solr界面功能2.png"></p><p><img src="https://upload-images.jianshu.io/upload_images/15645795-e7752c1bb89d3ed1.png" alt="Solr界面功能3.png"></p><p><img src="https://upload-images.jianshu.io/upload_images/15645795-e33d2bf46d0a14e3.png" alt="Solr界面功能4.png"></p><p><img src="https://upload-images.jianshu.io/upload_images/15645795-ba7bba480f988d86.png" alt="Solr界面功能5.png"></p><h4 id="8-Solr全量更新-增量更新-要配置数据库"><a href="#8-Solr全量更新-增量更新-要配置数据库" class="headerlink" title="8.Solr全量更新/增量更新 -要配置数据库"></a>8.Solr全量更新/增量更新 -要配置数据库</h4><h5 id="1、全量更新"><a href="#1、全量更新" class="headerlink" title="1、全量更新"></a>1、全量更新</h5><p>参考 5.solr连接数据库 配置 ，完成后：<br><img src="https://upload-images.jianshu.io/upload_images/15645795-a982e542a4b04a89.png" alt="solr全量更新.png"></p><p>记住：clean=true、commit=true</p><h5 id="2、增量更新"><a href="#2、增量更新" class="headerlink" title="2、增量更新"></a>2、增量更新</h5><p><strong>1.首先要弄懂几个必要的属性 ，以及数据库建表事项 ，和dataimporter.properties 、data-config.xml里面的数据</strong></p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&lt;!--  transformer 格式转化：HTMLStripTransformer 索引中忽略HTML标签   ---&gt;</span><br><span class="line">&lt;!--  query:查询数据库表符合记录数据   ---&gt;</span><br><span class="line">&lt;!--  deltaQuery:增量索引查询主键ID    ---&gt;    注意这个只能返回ID字段</span><br><span class="line">&lt;!--  deltaImportQuery:增量索引查询导入数据  ---&gt;</span><br><span class="line">&lt;!--  deletedPkQuery:增量索引删除主键ID查询  ---&gt; 注意这个只能返回ID字段</span><br></pre></td></tr></table></figure><p><strong>2.数据库配置注意事项</strong></p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">1.如果只涉及添加 ，与修改业务 ，那么数据库里只需额外有一个timpstamp字段</span><br><span class="line">就可以了 ，默认值为当前系统时间 ，CURRENT_TIMESTAMP</span><br><span class="line">2.如果还涉及删除业务 ，那么数据里就需额外再多添加一个字段isdelete ，int类型的</span><br><span class="line">用0,1来标识 ，此条记录是否被删除</span><br></pre></td></tr></table></figure><p><strong>3.dataimporter.properties</strong></p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">这个配置文件很重要 ，它是用来记录当前时间与上一次修改时间的 ，通过它能够找出 ，那些 ，新添加的 ，修改的 ，或删除的记录标识 ，此条记录是否被删除的记录</span><br></pre></td></tr></table></figure><p><strong>4.增量更新就是在全量更新的基础上加上一些配置 ，data-config.xml配置如下：</strong></p><p>原配置：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dataConfig</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">dataSource</span> </span></span><br><span class="line"><span class="tag">	<span class="attr">type</span>=<span class="string">"JdbcDataSource"</span> </span></span><br><span class="line"><span class="tag">	<span class="attr">driver</span>=<span class="string">"oracle.jdbc.OracleDriver"</span> </span></span><br><span class="line"><span class="tag">	<span class="attr">url</span>=<span class="string">"jdbc:oracle:thin:@localhost:1521:ORCL"</span> </span></span><br><span class="line"><span class="tag">	<span class="attr">user</span>=<span class="string">"duke"</span> </span></span><br><span class="line"><span class="tag">	<span class="attr">password</span>=<span class="string">"duke"</span> /&gt;</span> </span><br><span class="line">	<span class="tag">&lt;<span class="name">document</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">entity</span> <span class="attr">name</span>=<span class="string">"userEntity"</span> <span class="attr">query</span>=<span class="string">"select ID, NAME,AGE from t_user"</span>&gt;</span></span><br><span class="line">            <span class="comment">&lt;!--查询的数据和数据库索引意义对应column 是查询的字段name 是solr索引对应的字段--&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">field</span> <span class="attr">column</span>=<span class="string">"ID"</span> <span class="attr">name</span>=<span class="string">"user_id"</span>/&gt;</span> </span><br><span class="line">			<span class="tag">&lt;<span class="name">field</span> <span class="attr">column</span>=<span class="string">"NAME"</span> <span class="attr">name</span>=<span class="string">"user_name"</span>/&gt;</span> </span><br><span class="line">			<span class="tag">&lt;<span class="name">field</span> <span class="attr">column</span>=<span class="string">"AGE"</span> <span class="attr">name</span>=<span class="string">"user_age"</span>/&gt;</span> </span><br><span class="line">		<span class="tag">&lt;/<span class="name">entity</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">document</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dataConfig</span>&gt;</span></span><br></pre></td></tr></table></figure><p>增量更新配置：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&lt;?xml version="1.0" encoding="UTF-8"?&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">dataConfig</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">dataSource</span> </span></span><br><span class="line"><span class="tag">	<span class="attr">type</span>=<span class="string">"JdbcDataSource"</span> </span></span><br><span class="line"><span class="tag">	<span class="attr">driver</span>=<span class="string">"oracle.jdbc.OracleDriver"</span> </span></span><br><span class="line"><span class="tag">	<span class="attr">url</span>=<span class="string">"jdbc:oracle:thin:@localhost:1521:ORCL"</span> </span></span><br><span class="line"><span class="tag">	<span class="attr">user</span>=<span class="string">"duke"</span> </span></span><br><span class="line"><span class="tag">	<span class="attr">password</span>=<span class="string">"duke"</span> /&gt;</span> </span><br><span class="line">	<span class="tag">&lt;<span class="name">document</span>&gt;</span></span><br><span class="line">		<span class="tag">&lt;<span class="name">entity</span> <span class="attr">name</span>=<span class="string">"userEntity"</span> <span class="attr">query</span>=<span class="string">"select ID,NAME,AGE from t_user"</span></span></span><br><span class="line"><span class="tag">		<span class="attr">deltaImportQuery</span> =<span class="string">"select ID,NAME,AGE from t_user t where t.ID='$&#123;dataimport.delta.id&#125;'"</span></span></span><br><span class="line"><span class="tag">		<span class="attr">deltaQuery</span> = <span class="string">"select ID from t_user t where t.LASTUPDATETIME='$&#123;dataimport.last_index_time&#125;'"</span></span></span><br><span class="line"><span class="tag">		<span class="attr">deletedPkQuery</span> = <span class="string">"select ID from t_user"</span>&gt;</span></span><br><span class="line">			<span class="tag">&lt;<span class="name">field</span> <span class="attr">column</span>=<span class="string">"ID"</span> <span class="attr">name</span>=<span class="string">"user_id"</span>/&gt;</span> </span><br><span class="line">			<span class="tag">&lt;<span class="name">field</span> <span class="attr">column</span>=<span class="string">"NAME"</span> <span class="attr">name</span>=<span class="string">"user_name"</span>/&gt;</span> </span><br><span class="line">			<span class="tag">&lt;<span class="name">field</span> <span class="attr">column</span>=<span class="string">"AGE"</span> <span class="attr">name</span>=<span class="string">"user_age"</span>/&gt;</span> </span><br><span class="line">			<span class="tag">&lt;<span class="name">field</span> <span class="attr">column</span>=<span class="string">"LASTUPDATETIME"</span> <span class="attr">name</span>=<span class="string">"user_lastUpdateTime"</span>/&gt;</span> </span><br><span class="line">		<span class="tag">&lt;/<span class="name">entity</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;/<span class="name">document</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dataConfig</span>&gt;</span></span><br></pre></td></tr></table></figure><p><strong>5.通过后台管理手动增量更新和通过浏览器手动更新</strong><br><img src="https://upload-images.jianshu.io/upload_images/15645795-2aae26ad752d1edc.png" alt="solr增量更新.png"></p><p>在浏览器直接输入网站 :</p><p>&lt; <a href="http://127.0.0.1:8983/solr/#/corename/dataimport//dataimport&gt;" target="_blank" rel="noopener">http://127.0.0.1:8983/solr/#/corename/dataimport//dataimport&gt;</a></p><p>记住：clean=false、commit=true</p><h4 id="9、solr-常见的自动更新方式"><a href="#9、solr-常见的自动更新方式" class="headerlink" title="9、solr 常见的自动更新方式"></a>9、solr 常见的自动更新方式</h4><h6 id="方式一：solr-自带的增量更新更新"><a href="#方式一：solr-自带的增量更新更新" class="headerlink" title="方式一：solr 自带的增量更新更新"></a>方式一：solr 自带的增量更新更新</h6><p>*<em>1.下载jar包 *</em></p><p>apache-solr-dataimportscheduler.jar、solr-dataimporthandler-7.0.0.jar、solr-dataimporthandler-extras-7.0.0.jar到 solr 项目的\WEB-INF\lib 目录下</p><p>apache-solr-dataimportscheduler 的下载地址:</p><p>链接：<a href="https://pan.baidu.com/s/110-F7DrO_4QEILWb6FFvzQ" target="_blank" rel="noopener">https://pan.baidu.com/s/110-F7DrO_4QEILWb6FFvzQ</a><br>提取码：yxm8</p><p><strong>2. 修改web.xml文件配置监听 ，在servlet节点前增加：</strong></p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">listener</span>&gt;</span></span><br><span class="line">       <span class="tag">&lt;<span class="name">listener-class</span>&gt;</span></span><br><span class="line">             org.apache.solr.handler.dataimport.scheduler.ApplicationListener</span><br><span class="line">       <span class="tag">&lt;/<span class="name">listener-class</span>&gt;</span></span><br><span class="line"> <span class="tag">&lt;/<span class="name">listener</span>&gt;</span></span><br></pre></td></tr></table></figure><p><strong>3.创建 dataimport.properties</strong></p><p>在solrHome(存储solr数据的目录) 的目录下创建conf文件夹,创建 dataimport.properties 文件 ，内容根据实际情况修改 ，内容如下：</p><figure class="highlight properties"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#################################################</span></span><br><span class="line"><span class="comment">#                                              #</span></span><br><span class="line"><span class="comment">#      dataimport scheduler properties        #</span></span><br><span class="line"><span class="comment">#                                              #</span></span><br><span class="line"><span class="comment">#################################################</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">#  tosync or not to sync</span></span><br><span class="line"><span class="comment">#  1- active; anything else - inactive</span></span><br><span class="line"><span class="comment"># 这里的配置不用修改</span></span><br><span class="line"><span class="attr">syncEnabled</span>=<span class="string">1</span></span><br><span class="line"> </span><br><span class="line"><span class="comment"># which cores to schedule</span></span><br><span class="line"><span class="comment">#  ina multi-core environment you can decide which cores you want syncronized</span></span><br><span class="line"><span class="comment"># leave empty or comment it out if using single-core deployment</span></span><br><span class="line"><span class="comment">#  修改成你所使用的core ，我这里是我自定义的core：simple</span></span><br><span class="line"><span class="attr">syncCores</span>=<span class="string">active</span></span><br><span class="line"> </span><br><span class="line"><span class="comment"># solr server name or IP address</span></span><br><span class="line"><span class="comment"># [defaults to localhost if empty]</span></span><br><span class="line"><span class="attr">这个一般都是localhost不会变</span></span><br><span class="line"><span class="attr">server</span>=<span class="string">localhost</span></span><br><span class="line"> </span><br><span class="line"><span class="comment"># solr server port</span></span><br><span class="line"><span class="comment"># [defaults to 80 if empty]</span></span><br><span class="line"><span class="comment">#  安装solr的tomcat端口 ，如果你使用的是默认的端口 ，就不用改了 ，否则改成自己的端口就好了</span></span><br><span class="line"><span class="attr">port</span>=<span class="string">8089</span></span><br><span class="line"> </span><br><span class="line"><span class="comment"># application name/context</span></span><br><span class="line"><span class="comment"># [defaults to current ServletContextListener's context (app) name]</span></span><br><span class="line"><span class="comment">#  这里默认不改</span></span><br><span class="line"><span class="attr">webapp</span>=<span class="string">solr</span></span><br><span class="line"> </span><br><span class="line"><span class="comment"># URL params [mandatory]</span></span><br><span class="line"><span class="comment"># remainder of URL</span></span><br><span class="line"><span class="comment">#  这里改成下面的形式 ，solr同步数据时请求的链接</span></span><br><span class="line"><span class="attr">params</span>=<span class="string">/dataimport?command=delta-import&amp;clean=false&amp;commit=true</span></span><br><span class="line"> </span><br><span class="line"><span class="comment"># schedule interval</span></span><br><span class="line"><span class="comment"># number of minutes between two runs</span></span><br><span class="line"><span class="comment"># [defaults to 30 if empty]</span></span><br><span class="line"><span class="comment">#这里是设置定时任务的 ，单位是分钟 ，也就是多长时间你检测一次数据同步 ，根据项目需求修改</span></span><br><span class="line"><span class="comment">#  开始测试的时候为了方便看到效果 ，时间可以设置短一点</span></span><br><span class="line"><span class="attr">interval</span>=<span class="string">1</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">#  重做索引的时间间隔 ，单位分钟 ，默认7200 ，即5天;</span></span><br><span class="line"><span class="comment">#  为空,为0,或者注释掉:表示永不重做索引</span></span><br><span class="line"><span class="attr">reBuildIndexInterval</span>=<span class="string">7200</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">#  重做索引的参数</span></span><br><span class="line"><span class="attr">reBuildIndexParams</span>=<span class="string">/select?qt=/dataimport&amp;command=full-import&amp;clean=true&amp;commit=true</span></span><br><span class="line"> </span><br><span class="line"><span class="comment">#  重做索引时间间隔的计时开始时间 ，第一次真正执行的时间=reBuildIndexBeginTime+reBuildIndexInterval*60*1000；</span></span><br><span class="line"><span class="comment">#  两种格式：2012-04-11 03:10:00 或者 03:10:00 ，后一种会自动补全日期部分为服务启动时的日期</span></span><br><span class="line"><span class="attr">reBuildIndexBeginTime</span>=<span class="string">03:10:00</span></span><br></pre></td></tr></table></figure><p>最后重启solr ，在数据库中添加一条数据 ，静等一分钟 ，然后query。因为我们设置的是一分钟监听一次</p><h6 id="方式二：使用windows-的计划任务进行增量更新"><a href="#方式二：使用windows-的计划任务进行增量更新" class="headerlink" title="方式二：使用windows 的计划任务进行增量更新"></a>方式二：使用windows 的计划任务进行增量更新</h6><p>此方法 ，用于tomcat下部署的solr。</p><p><strong>1.在windows开始那里搜索“计划任务”</strong><br><img src="https://upload-images.jianshu.io/upload_images/15645795-2abf126a9d3bd475.jpg" alt="solr计划任务1.jpg"></p><p><strong>2.创建一个新的计划任务</strong><br><img src="https://upload-images.jianshu.io/upload_images/15645795-66254e8783595611.jpg" alt="solr计划任务2.jpg"></p><p><strong>3.对计划任务的常规、触发器、操作 进行设置</strong></p><p><img src="https://upload-images.jianshu.io/upload_images/15645795-ebbc86973da7a007.jpg" alt="solr计划任务3.jpg"><br><img src="https://upload-images.jianshu.io/upload_images/15645795-5c0bfceb26de7c2c.jpg" alt="solr计划任务4.jpg"><br><img src="https://upload-images.jianshu.io/upload_images/15645795-7c5e4df5e44d12a8.jpg" alt="solr计划任务5.jpg"></p><p><strong>4.启动计划任务</strong></p><p><strong>5.solr.bat 中的内容为（使用curl进行模拟请求 ，curl 需要下载）：</strong></p><figure class="highlight bat"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">curl  http://localhost:<span class="number">8089</span>/solr/active/dataimport?command=delta-import^&amp;clean=false^&amp;commit=true</span><br></pre></td></tr></table></figure><p><strong>6.windows 的curl 需要下载配置环境变量（和jdk的差不多） ，curl下载地址为:</strong></p><p>链接：<a href="https://pan.baidu.com/s/1CArPu0vdPGGWRfo8KuZxWg" target="_blank" rel="noopener">https://pan.baidu.com/s/1CArPu0vdPGGWRfo8KuZxWg</a> 提取码：09ks (64位系统的 ，32位的可以去官网下载)</p><h6 id="方式三：linux下使用-crontab实现增量更新"><a href="#方式三：linux下使用-crontab实现增量更新" class="headerlink" title="方式三：linux下使用 crontab实现增量更新"></a>方式三：linux下使用 crontab实现增量更新</h6><p>此方法 ，用于tomcat下部署的solr。</p><p><strong>1.修改crontab的配置文件：vim /etc/crontab</strong></p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">crontab -e</span><br><span class="line">*&#x2F;5 * * * * curl  http:&#x2F;&#x2F;localhost:8089&#x2F;solr&#x2F;active&#x2F;dataimport?command&#x3D;delta-import^&amp;clean&#x3D;false^&amp;commit&#x3D;true</span><br></pre></td></tr></table></figure><p>注：5分钟执行一次增量索引（可根据实际业务调整时间）</p></div><div class="popular-posts-header"><p style="font-size:18px;color:red;margin:0 0 5px 0">相关文章推荐：</p></div><ul class="popular-posts"><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\1847461252.html" rel="bookmark">springboot+redis项目实战完整篇</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\477243062.html" rel="bookmark">ehcache、redis、memcached缓存的应用场景</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\379612345.html" rel="bookmark">SpringBoot配置-Hibernate-Validate</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\1127863787.html" rel="bookmark">springboot+Dozer+maven测试及项目实战演示</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\236595351.html" rel="bookmark">史上最详细springBoot初建</a></div></li><li class="popular-posts-item"><div class="popular-posts-title"><a href="\posts\3431840903.html" rel="bookmark">springboot-redis-session配置两种方式</a></div></li></ul><div><div style="text-align:center;color:#ccc;font-size:14px">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div></div><div class="reward-container"><div><p style="font-size:14px;color:#34495e;margin:0 0 5px 0">赞赏一下吧～ 还可以关注公众号订阅最新内容</p></div><button disable="enable" onclick="var qr = document.getElementById(&quot;qr&quot;); qr.style.display = (qr.style.display === 'none') ? 'block' : 'none';">打赏</button><div id="qr" style="display:none"><div style="display:inline-block"><img src="/my-images/WeChat.png" alt="宇宙小神特别萌 微信支付"><p>微信支付</p></div><div style="display:inline-block"><img src="/my-images/Alipay.png" alt="宇宙小神特别萌 支付宝"><p>支付宝</p></div></div></div><footer class="post-footer"><div class="post-tags"><a href="/tags/SpringBoot/" rel="tag"><i class="fa fa-tag"></i> SpringBoot</a></div><div class="post-nav"><div class="post-nav-item"><a href="/posts/236595351.html" rel="prev" title="史上最详细springBoot初建"><i class="fa fa-chevron-left"></i> 史上最详细springBoot初建</a></div><div class="post-nav-item"><a href="/posts/1847461252.html" rel="next" title="springboot+redis项目实战完整篇">springboot+redis项目实战完整篇 <i class="fa fa-chevron-right"></i></a></div></div></footer></article></div></div><div class="comments" id="valine-comments"></div><script>window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }</script></div><div class="toggle sidebar-toggle"><span class="toggle-line toggle-line-first"></span> <span class="toggle-line toggle-line-middle"></span> <span class="toggle-line toggle-line-last"></span></div><aside class="sidebar"><div class="sidebar-inner"><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc">文章目录</li><li class="sidebar-nav-overview">站点概览</li></ul><div class="post-toc-wrap sidebar-panel"><div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#一、Solr"><span class="nav-text">一、Solr</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#1、下载-zip-为windows版"><span class="nav-text">1、下载 .zip 为windows版</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2、启动、关闭solr"><span class="nav-text">2、启动、关闭solr</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#3、创建core文件夹"><span class="nav-text">3、创建core文件夹</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#创建core文件夹方式一-推荐-："><span class="nav-text">创建core文件夹方式一(推荐)：</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#创建core文件夹方式二："><span class="nav-text">创建core文件夹方式二：</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#4、创建springboot项目和测试代码"><span class="nav-text">4、创建springboot项目和测试代码</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#其他问题："><span class="nav-text">其他问题：</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#5-solr连接数据库"><span class="nav-text">5.solr连接数据库</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1、添加驱动依赖包"><span class="nav-text">1、添加驱动依赖包</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2、配置dataimporthandler相关包"><span class="nav-text">2、配置dataimporthandler相关包</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#3、添加数据库配置"><span class="nav-text">3、添加数据库配置</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#4、创建data-config2-xml数据库连接配置"><span class="nav-text">4、创建data-config2.xml数据库连接配置</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#5、配置managed-schema"><span class="nav-text">5、配置managed-schema</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#6、验证是否成功"><span class="nav-text">6、验证是否成功</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#6-solr-安装中文分词器"><span class="nav-text">6.solr 安装中文分词器</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-Solr-界面功能"><span class="nav-text">7.Solr 界面功能</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#8-Solr全量更新-增量更新-要配置数据库"><span class="nav-text">8.Solr全量更新&#x2F;增量更新 -要配置数据库</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#1、全量更新"><span class="nav-text">1、全量更新</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#2、增量更新"><span class="nav-text">2、增量更新</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#9、solr-常见的自动更新方式"><span class="nav-text">9、solr 常见的自动更新方式</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#方式一：solr-自带的增量更新更新"><span class="nav-text">方式一：solr 自带的增量更新更新</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#方式二：使用windows-的计划任务进行增量更新"><span class="nav-text">方式二：使用windows 的计划任务进行增量更新</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#方式三：linux下使用-crontab实现增量更新"><span class="nav-text">方式三：linux下使用 crontab实现增量更新</span></a></li></ol></li></ol></li></ol></div></div><div class="site-overview-wrap sidebar-panel"><div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person"><img class="site-author-image" itemprop="image" alt="宇宙小神特别萌" src="/my-images/avatar.gif"><p class="site-author-name" itemprop="name">宇宙小神特别萌</p><div class="site-description" itemprop="description">人生就是一次幸运的旅行！</div></div><div class="site-state-wrap motion-element"><nav class="site-state"><div class="site-state-item site-state-posts"><a href="/archives/"><span class="site-state-item-count">116</span> <span class="site-state-item-name">文章</span></a></div><div class="site-state-item site-state-tags"><a href="/tags/"><span class="site-state-item-count">27</span> <span class="site-state-item-name">标签</span></a></div></nav></div><div class="links-of-author motion-element"><span class="links-of-author-item"><a href="https://github.com/zhengjiaao" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;zhengjiaao" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a> </span><span class="links-of-author-item"><a href="https://www.jianshu.com/u/70d69269bd09" title="简书 → https:&#x2F;&#x2F;www.jianshu.com&#x2F;u&#x2F;70d69269bd09" rel="noopener" target="_blank"><i class="fa fa-fw fa-book"></i>简书</a> </span><span class="links-of-author-item"><a href="/atom.xml" title="RSS → &#x2F;atom.xml"><i class="fa fa-fw fa-rss"></i>RSS</a></span></div><div class="links-of-blogroll motion-element"><div class="links-of-blogroll-title"><i class="fa fa-fw fa-link"></i> 推荐阅读</div><ul class="links-of-blogroll-list"><li class="links-of-blogroll-item"><a href="https://github.com/spring-projects" title="https:&#x2F;&#x2F;github.com&#x2F;spring-projects" rel="noopener" target="_blank">spring-projects</a></li><li class="links-of-blogroll-item"><a href="http://www.alloyteam.com/nav/" title="http:&#x2F;&#x2F;www.alloyteam.com&#x2F;nav&#x2F;" rel="noopener" target="_blank">Web前端导航</a></li><li class="links-of-blogroll-item"><a href="http://www.chuangzaoshi.com/code" title="http:&#x2F;&#x2F;www.chuangzaoshi.com&#x2F;code" rel="noopener" target="_blank">创造狮导航</a></li></ul></div></div></div></aside><div id="sidebar-dimmer"></div></div></main><footer class="footer"><div class="footer-inner"><div class="copyright">&copy; <span itemprop="copyrightYear">2020</span> <span class="with-love"><i class="fa fa-heart"></i> </span><span class="author" itemprop="copyrightHolder">宇宙小神特别萌</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-area-chart"></i> </span><span title="站点总字数">1.2m</span> <span class="post-meta-divider">|</span> <span class="post-meta-item-icon"><i class="fa fa-coffee"></i> </span><span title="站点阅读时长">17:41</span></div><div class="busuanzi-count"><script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span class="post-meta-item" id="busuanzi_container_site_uv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-user"></i> </span><span class="site-uv" title="总访客量"><span id="busuanzi_value_site_uv"></span> </span></span><span class="post-meta-divider">|</span> <span class="post-meta-item" id="busuanzi_container_site_pv" style="display:none"><span class="post-meta-item-icon"><i class="fa fa-eye"></i> </span><span class="site-pv" title="总访问量"><span id="busuanzi_value_site_pv"></span></span></span></div></div></footer></div><script src="//cdn.jsdelivr.net/npm/animejs@3.1.0/lib/anime.min.js"></script><script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script><script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.1/velocity.min.js"></script><script src="//cdnjs.cloudflare.com/ajax/libs/velocity/1.2.1/velocity.ui.min.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/schemes/muse.js"></script><script src="/js/next-boot.js"></script><script src="/js/bookmark.js"></script><script>!function(){var t=document.createElement("script"),e=window.location.protocol.split(":")[0];t.src="https"===e?"https://zz.bdstatic.com/linksubmit/push.js":"http://push.zhanzhang.baidu.com/push.js";var s=document.getElementsByTagName("script")[0];s.parentNode.insertBefore(t,s)}()</script><script src="/js/local-search.js"></script><script>NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//cdnjs.cloudflare.com/ajax/libs/valine/1.3.10/Valine.min.js', () => {
    <!--var GUEST = ['nick', 'mail', 'link'];-->
    var GUEST = ['nick', 'mail'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el: '#valine-comments',
      verify: false,
      notify: false,
      appId: 'OuyHeA0XGL8hK4vgbqL0iERx-gzGzoHsz',
      appKey: 'L58VglKmWULcGK2W2AN7kWzM',
      placeholder: "留下邮箱，有回复时你将收到提醒，邮箱不会被公开。",
      avatar: 'wavatar',
      meta: guest,
      pageSize: '10' || 10,
      visitor: true,
      lang: 'zh-cn' || 'zh-cn',
      path: location.pathname,
      recordIP: true,
      serverURLs: ''
    });
  }, window.Valine);
});</script><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({pluginRootPath:"live2dw/",pluginJsPath:"lib/",pluginModelPath:"assets/",tagMode:!1,model:{jsonPath:"/live2dw/assets/wanko.model.json"},display:{position:"right",width:150,height:300},mobile:{show:!1},log:!1})</script></body><script type="text/javascript" src="/js/src/activetitle.js"></script></html><!-- rebuild by neat -->